// ----------------------------------------------------------------------------

function ASTParse(x) {
    var result = %JsonAstParse(x);
    return result;
}

function ASTEvaluate(text) {
  var s = $String(text);
  // var f = %CompileString("(" + text + ")", true);
  var f = %CompileString(text, null); // "null" sets JSON_AST
  return f();
}

function SetupAST() {
  // Initialize the AST object
  var ast = new $Object();

  // Install the functions
  InstallFunctions(ast, DONT_ENUM, $Array(
    "parse", ASTParse,
    "evaluate", ASTEvaluate
  ));
  
  // Add AST object to the JSON object
  %SetProperty($JSON,
               "AST",
               ast,
               DONT_ENUM); // DONT_ENUM |  DONT_DELETE | READ_ONLY);
}

SetupAST();

